package cn.gudian.cms.utils


/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-5-9
 * Time: 20:38:08
 * To change this template use File | Settings | File Templates.
 */
class StringUtil {
  /**
   * 截取字符串 可传入带有html标签的字符串
   * @param str   传入字符串
   * @param number  截取长度
   * @return    返回字符串
   */

  public static String subString(String str, int number) {
    String content = null;
    if (!str || !number) {
      return ""
    }
    content = htmlToString(str);
    if (content.length() < number) {
      return content
    }else {
      content = content.substring(0, number) + "......"
      return content
    }

  }

  /**
   * 将带有html标签字符串去除html标签
   * @param html
   * @return
   */
  public static String htmlToString(String html) {
    String content = null;
    try {
      content = html
      /** 剔出<html>的标签       */
      content = content.replaceAll("<[^>]+>", "");
      content = content.replace("&nbsp;", "");
      content = content.replace(".", "");
      content = content.replace("\"", "‘");
      content = content.replace("'", "‘");
    } catch (Exception e) {

    }
    return content;
  }
}